﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace IRobot
{
    class Program
    {
        static void Main(string[] args)
        {
            int roomSize=0;
            int dirtyCellsAllowed=-1;
            string searchTypeString = "";


            Console.WriteLine("\n-----------------------------\n  IROBOT - vacuum cleaner\n-----------------------------\n\n" +
                              "Use:   clean [ BFS | DFS | BEFS ] [Room-Size] [Allowed-dirty-Cells]\n\n" +
                             "Example:   clean BFS 5 8\n"+
                             "--------------------------------------------------------------------------------\n\n"
                              );

            try
            {
                //cmd line args checks
                if (args.Count() < 4)
                {
                    Console.WriteLine("\nInvalid Command line   -   there are less than 4 arguments.  \n Example:  clean BFS 5 8\n\n");
                    return;
                }

                searchTypeString = args[1];
                roomSize = Convert.ToInt32(args[2]);
                dirtyCellsAllowed = Convert.ToInt32(args[3]);

                if (args[0] != "clean")
                {
                    Console.WriteLine("Invalid Command line   -   Only \"clean\" option is valid.   \n Example:  clean BFS 5 8\n\n");
                    return;
                }
                if ((args[1] != "BFS") && (args[1] != "DFS") && (args[1] != "BEFS"))
                {
                    Console.WriteLine("Invalid Command line   -   Valid search types: BFS|DFS|BEFS.   \n Example:  clean BFS 5 8\n\n");
                    return;
                }
                if (roomSize < 0 || dirtyCellsAllowed < 0)
                {
                    Console.WriteLine("Invalid Command line   -   room size and Allowed-dirty-Cells should be greater than 0.   \n Example:  clean BFS 5 8\n\n");
                    return;
                }
                        
            }
            catch (Exception ex)
            {
                Console.WriteLine("Bad input!\n");
            }

            var robot = new MeRobot(roomSize, dirtyCellsAllowed);
            var searchType = (SearchType)Enum.Parse(typeof(SearchType), args[1]);
            robot.Clean(searchType);
            return; 
        }
    }
}
